/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.rw.table;

import com.rw.table.editor.ICellEditor;
import com.rw.table.formatter.ICellFormatter;
import com.rw.table.formatter.StringCellFormatter;
import com.rw.table.render.ICellRenderer;
import com.rw.table.render.LabelCellRenderer;

/**
 *
 * @author Rene Tapia
 */
public abstract class APropertyTableModel extends ATableModel {

    private LabelCellRenderer labelRenderer;
    private StringCellFormatter strFormatter;

    public abstract ICellRenderer getPropertyRenderer(int row);

    public abstract ICellEditor getPropertyEditor(int row);

    public abstract ICellFormatter getPropertyFormatter(int row);

    public abstract String getPropertyName(int row);

    public abstract Object getPropertyValue(int row);

    public abstract void setPropertyValue(Object value, int row);

    public abstract ATableAction getPropertyEditableByClickAction(int row);

    public APropertyTableModel() {
        this.labelRenderer = new LabelCellRenderer();
        this.strFormatter = new StringCellFormatter();
    }

    @Override
    public String getColumnName(int column) {
        return column == 0 ? "Atributo" : "Valor del Atributo";
    }

    @Override
    public int getColumnCount() {
        return 2;
    }

    @Override
    public ICellRenderer getRenderer(int row, int column) {
        if (column == 0) {
            return labelRenderer;
        } else {
            return getPropertyRenderer(row);
        }
    }

    @Override
    public ICellEditor getEditor(int row, int column) {
        if (column == 0) {
            return null;
        } else {
            return getPropertyEditor(row);
        }
    }

    @Override
    public ICellFormatter getFormatter(int row, int column) {
        if (column == 0) {
            return strFormatter;
        } else {
            return getPropertyFormatter(row);
        }
    }

    @Override
    public Object getValueAt(int rowIndex, int columnIndex) {
        if (columnIndex == 0) {
            return getPropertyName(rowIndex);
        } else {
            return getPropertyValue(rowIndex);
        }
    }

    @Override
    public void setValueAt(Object value, int rowIndex, int columnIndex) {
        if (columnIndex == 1) {
            setPropertyValue(value, rowIndex);
        }
    }

    @Override
    public ATableAction getEditableByClickAction(int row, int columnIndex) {
        if (columnIndex == 0) {
            return null;
        } else {
            return getPropertyEditableByClickAction(row);
        }
    }
}
